$(function () {
    findById();
})

/**
 * 查询id
 */
function findById() {
    //得到session中的navId
    let id = sessionStorage.getItem("hrId");
    let result = myAjax("/admin/hr/findById", {id: id},"post");
    console.log(result);
    if (result != null) {
        setData(result.model);
    }
}

//赋值
function setData(data) {
    $("#title").val(data.title);
    $("#href").val(data.href);
    $("#contentOne").val(data.contentOne);
    $("#contentTwo").val(data.contentTwo);
    $("input[name='status'][value=" + data.status + "]").attr("checked", true);
    $("#showImg").attr("src",data.img);
}


//返回用户查询结果页面
function goBack() {
    $('.right').load('/html/admin/hr/hrManage.html');
}

function save() {
    let data = new FormData();
    data.append("id",sessionStorage.getItem("hrId"));
    data.append("title",$("#title").val());
    data.append("href",$("#href").val());
    data.append("status", $("input:radio[name='status']:checked").val());
    data.append("contentOne",$("#contentOne").val());
    data.append("contentTwo",$("#contentTwo").val());
    data.append("img", $("#img")[0].files[0]);
    let result = myImgAjax("/adminFile/hr/update",data,"post");
    if(result.result === "success"){
        alert("修改成功！");
        $('.right').load('/html/admin/hr/hrManage.html');
    }else{
        alert("修改失败！");
    }
}





